package name.fowler.refactoring.simplestore;

import com.google.common.collect.Lists;
import name.fowler.refactoring.simplestore.dao.CustomerDao;
import name.fowler.refactoring.simplestore.model.Customer;
import name.fowler.refactoring.simplestore.model.Movie;
import name.fowler.refactoring.simplestore.model.Rental;
import name.fowler.refactoring.simplestore.model.pricecode.PriceCodeManager;
import name.fowler.refactoring.simplestore.service.ReportService;

import java.util.List;

class MainClass {

    public static void main(String[] args) {
        Movie movCinderella = new Movie("Cinderella", PriceCodeManager.getChildrens());
        Movie movStarWars = new Movie("Star Wars", PriceCodeManager.getRegular());
        Movie movGladiator = new Movie("Gladiator", PriceCodeManager.getNewRelease());
        Movie movDeepThroat = new Movie("Deep Throat", PriceCodeManager.getRegular());
        Movie movKickAss = new Movie("Kick-Ass", PriceCodeManager.getNewRelease());

        Customer custMickeyMouse = new Customer("Mickey Mouse");
        Customer custDonaldDuck = new Customer("Donald Duck");

        Rental rental1 = new Rental(Lists.newArrayList(movCinderella, movStarWars), 5);
        Rental rental2 = new Rental(Lists.newArrayList(movGladiator), 2);
        Rental rental3 = new Rental(Lists.newArrayList(movDeepThroat, movKickAss), 6);

        custMickeyMouse.addRental(rental1);
        custMickeyMouse.addRental(rental2);
        custDonaldDuck.addRental(rental3);

        List<Customer> customers = Lists.newArrayList(custMickeyMouse, custDonaldDuck);

        CustomerDao customerDao = new CustomerDao();
        customerDao.save(customers);

        ReportService reportService = new ReportService(customerDao);

        try {
            System.out.println(reportService.buildTextCustomerReport("Mickey Mouse"));
            System.out.println(reportService.buildTextCustomerReport("Donald Duck"));
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}

